home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Standard Catalog Package / DTS AddressOMatic / Src / AOMUpdatePanel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  7.2 KB  |  286 lines  |  [TEXT/KAHL]

  1. /*                                AOMUpdatePanel.c                                */
  2. /*
  3.  * AddressOMatic Sample
  4.  * AOMUpdatePanel.c
  5.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  6.  */
  7. #include "IconSuite.h"
  8. #include "AddressOMaticPrivate.h"
  9. #include <Palettes.h>
  10. #include <TextEdit.h>
  11.  
  12. /*
  13.  * These are the colors we use. They are in the Apple Icon Color 'clut'
  14.  */
  15.  
  16. const RGBColor    _AOMBackgroundColor        = kAOMBackgroundColor;
  17. const RGBColor    _AOMShadowColor            = kAOMShadowColor;
  18. const RGBColor    _AOMDarkBevelColor        = kAOMDarkBevelColor;
  19. const RGBColor    _AOMLightBevelColor        = kAOMLightBevelColor;
  20. const RGBColor    _AOMWhiteColor            = kAOMWhiteColor;
  21. const RGBColor    _AOMBlackColor            = kAOMBlackColor;
  22.  
  23. /*
  24.  * Redraw the panel. This is called by the user application in response to
  25.  * an update event. The GrafPort must be set to the panel window.
  26.  */
  27. pascal OSErr
  28. AOMUpdatePanel(
  29.         register AddressOMaticPtr    aomPtr,                /* The panel            */
  30.         RgnHandle                    drawRgn                /* What to draw            */
  31.     )
  32. {
  33.         OSErr                        status;
  34.         AOMSaveState                saveState;
  35.         short                        i;
  36.         Rect                        viewRect;
  37.  
  38.         status = noErr;
  39.         if (AOM.isVisible) {
  40.             _AOMSaveState(aomPtr, kAOMLabelFontStyle, &saveState);
  41.             EraseRect(&INTERIOR);
  42.             /*
  43.              * The panel frame
  44.              */
  45.             PenNormal();
  46.             viewRect = INTERIOR;
  47.             FrameRect(&viewRect);
  48.             if (IS_COLOR(AOM.window) && COLOR_DEPTH(AOM.window) >= 4)
  49.                 RGBForeColor(&_AOMShadowColor);
  50.             /*
  51.              * Draw the drop-shadow.
  52.              */
  53.             PenSize(kAOMDropShadowWidth, kAOMDropShadowWidth);
  54.             MoveTo(viewRect.left + kAOMDropShadowWidth, viewRect.bottom);
  55.             LineTo(viewRect.right, viewRect.bottom);
  56.             LineTo(viewRect.right, viewRect.top + kAOMDropShadowWidth);
  57.             PenNormal();
  58.             if (IS_COLOR(AOM.window) && COLOR_DEPTH(AOM.window) >= 4) {
  59.                 InsetRect(&viewRect, 1, 1);
  60.                 RGBForeColor(&_AOMLightBevelColor);
  61.                 MoveTo(viewRect.left, viewRect.bottom - 1);
  62.                 LineTo(viewRect.left, viewRect.top);
  63.                 LineTo(viewRect.right - 1, viewRect.top);
  64.                 RGBForeColor(&_AOMDarkBevelColor);
  65.                 MoveTo(viewRect.left, viewRect.bottom - 1);
  66.                 LineTo(viewRect.right - 1, viewRect.bottom - 1);
  67.                 LineTo(viewRect.right - 1, viewRect.top);
  68.                 RGBForeColor(&_AOMBlackColor);
  69.                 RGBBackColor(&_AOMBackgroundColor);
  70.             }
  71.             /*
  72.              * Update controls. Update the visible SDP panel. This could be
  73.              * done more efficiently, especially since  the update event already
  74.              * drew the control.
  75.              */
  76.             if (AOM.doneButton != NULL)
  77.                 Draw1Control(AOM.doneButton);
  78.             if (AOM.ccButton != NULL)
  79.                 Draw1Control(AOM.ccButton);
  80.             if (AOM.toButton != NULL) {
  81.                 Draw1Control(AOM.toButton);
  82.                 _AOMDrawDefaultButtonOutline(AOM.toButton, AOM.isTarget);
  83.             }
  84.             /*
  85.              * Plot the radio buttons.
  86.              */
  87.             for (i = 0; i < kAOMRadioButtons; i++) {
  88.                 _AOMPlotIcon(
  89.                     aomPtr, i,
  90.                     (_AOMRadioInfo[i].modeBit == AOM.currentMode)
  91.                 );
  92.             }                                            /* For all icons        */
  93.             switch (AOM.currentMode) {
  94.             case kAOMEnablePDBit:
  95.                 status = _AOMPanelUpdate(aomPtr, AOM.pdPanel, drawRgn);
  96.                 break;
  97.             case kAOMEnablePanelBit:
  98.                 status = _AOMPanelUpdate(aomPtr, AOM.browsePanel, drawRgn);
  99.                 break;
  100.             case kAOMEnableFindBit:
  101.                 status = _AOMFindUpdate(aomPtr, drawRgn);
  102.                 break;
  103. #ifdef ENABLE_TYPEIN
  104.             case kAOMEnableTypeInBit:
  105.                 status = _AOMTypeInUpdate(aomPtr, drawRgn);
  106.                 break;
  107. #endif
  108.             }
  109.             _AOMUpdateSpinner(aomPtr);
  110.             _AOMDrawTitleString(aomPtr);
  111.             _AOMRestoreState(&saveState);
  112.         }                                                /* If panel is visible    */
  113.         return (status);
  114. }
  115.  
  116.  
  117. void
  118. _AOMDrawTitleString(
  119.         register AddressOMaticPtr    aomPtr
  120.     )
  121. {
  122.         AOMSaveState                saveState;
  123.         Str255                        panelTitle;
  124.  
  125.         _AOMSaveState(aomPtr, kAOMLabelFontStyle, &saveState);
  126.         panelTitle[0] = 0;
  127.         switch (AOM.currentMode) {
  128.         case kAOMEnablePDBit:
  129.             GetIndString(panelTitle, AOM.stringsResID, kAOMPDTitleString);
  130.             break;
  131.         case kAOMEnablePanelBit:
  132.             GetIndString(panelTitle, AOM.stringsResID, kAOMPanelTitleString);
  133.             break;
  134.         case kAOMEnableFindBit:
  135.             GetIndString(panelTitle, AOM.stringsResID, kAOMFindTitleString);
  136.             break;
  137. #ifdef ENABLE_TYPEIN
  138.         case kAOMEnableTypeInBit:
  139.             GetIndString(panelTitle, AOM.stringsResID, kAOMTypeInTitleString);
  140.             break;
  141. #endif
  142.         }
  143.         if (panelTitle[0] > 0) {
  144.             TextBox(
  145.                 &panelTitle[1],
  146.                 panelTitle[0],
  147.                 &TITLE,
  148.                 teJustCenter
  149.             );
  150.         }
  151.         _AOMRestoreState(&saveState);
  152. }
  153.  
  154. /*
  155.  * Plot one of our icons. Ignore errors.
  156.  */
  157. void
  158. _AOMPlotIcon(
  159.         register AddressOMaticPtr    aomPtr,
  160.         short                        index,
  161.         Boolean                        isSelected
  162.     )
  163. {
  164.         Rect                        viewRect;
  165.         register AOMRadioButtonPtr    buttonPtr;
  166. #define BUTTON    (*buttonPtr)
  167.         
  168.         buttonPtr = (AOMRadioButtonPtr) &_AOMRadioInfo[index];
  169.         viewRect = RADIO(index);
  170.         viewRect.right = viewRect.left + 32;
  171.         viewRect.bottom = viewRect.top + 32;
  172.         (void) PlotIconID(
  173.                 &viewRect,
  174.                 (atTop | atLeft),
  175.                 (AOM.radioEnable[index]) ? ttNone : ttDisabled,
  176.                 (isSelected) ? BUTTON.selected : BUTTON.normal
  177.             );
  178. }
  179.  
  180. /*
  181.  * _AOMDrawDefaultButtonOutline
  182.  *    (Adapted from Steve Falkenberg's sample)
  183.  * Note: this function is essentially independent of the rest of
  184.  * the AddressOMatic. 
  185.  */
  186. void
  187. _AOMDrawDefaultButtonOutline(
  188.         ControlHandle                theControl,
  189.         Boolean                        doDrawButton    /* FALSE erases the button        */
  190.     )
  191. {
  192.         GrafPtr                        savePort;
  193.         PenState                    savePenState;
  194.         Rect                        viewRect;
  195.         short                        buttonOval;
  196.         Boolean                        newGray;
  197.         RGBColor                    saveBackground;
  198.         RGBColor                    saveForeground;
  199.         RGBColor                    grayForeground;
  200.  
  201.         GetPort(&savePort);
  202.         SetPort((**theControl).contrlOwner);
  203.         GetPenState(&savePenState);
  204.         PenNormal();
  205.         viewRect = (**theControl).contrlRect;
  206.         InsetRect(&viewRect, -kButtonDefaultInset, -kButtonDefaultInset);
  207.         PenSize(kButtonDefaultPenSize, kButtonDefaultPenSize);
  208.         buttonOval = (height(viewRect) / 2) + 2;
  209.         if (doDrawButton == FALSE) {
  210.             /*
  211.              * Erase the default ring (but not the button itself).
  212.              */
  213.             PenMode(patBic);
  214.             FrameRoundRect(&viewRect, buttonOval, buttonOval);
  215.         }
  216.         else {
  217.             /*
  218.              * Note that newGray will be FALSE if color is not available.
  219.              */
  220.             newGray = FALSE;
  221.             if ((**theControl).contrlHilite != kActiveControl) {
  222.                 /*
  223.                  * Draw a gray outline
  224.                  */
  225.                 if (IS_COLOR((**theControl).contrlOwner)) {
  226.                     GetBackColor(&saveBackground);
  227.                     GetForeColor(&saveForeground);
  228.                     grayForeground = saveForeground;
  229.                     newGray = GetGray(
  230.                                 _AOMGetDeviceFromRect(&viewRect),
  231.                                 &saveBackground,
  232.                                 &grayForeground
  233.                             );
  234.                 }
  235.                 if (newGray)
  236.                     RGBForeColor(&grayForeground);
  237.                 else {
  238.     #if THINK_C
  239.                     PenPat(qd.gray);
  240.     #else
  241.                     PenPat(&qd.gray);
  242.     #endif
  243.                 }
  244.             }
  245.             FrameRoundRect(&viewRect, buttonOval, buttonOval);
  246.             if (newGray)
  247.                 RGBForeColor(&saveForeground);
  248.         }
  249.         SetPenState(&savePenState);
  250.         SetPort(savePort);
  251. }
  252.  
  253. /*
  254.  * This is called by functions (such as _AOMDrawDefaultButtonOutline)
  255.  * that need to determine whether a control or window element
  256.  * should be drawn in color.
  257.  */
  258. GDHandle
  259. _AOMGetDeviceFromRect(
  260.         const Rect                    *viewRect
  261.     )
  262. {
  263.         GDHandle                    device;
  264.         Point                        viewCenter;
  265.         
  266.         SetPt(
  267.             &viewCenter,
  268.             viewRect->left + width(*viewRect) / 2,
  269.             viewRect->top + height(*viewRect) / 2
  270.         );
  271.         LocalToGlobal(&viewCenter);
  272.         for (device = GetDeviceList();
  273.                 device != NULL;
  274.                 device = GetNextDevice(device)) {
  275.             if (TestDeviceAttribute(device, screenDevice)
  276.              && TestDeviceAttribute(device, screenActive)
  277.              && PtInRect(viewCenter, &(**device).gdRect))
  278.                 break;
  279.         }
  280.         if (device == NULL)
  281.             device = GetMainDevice();
  282.         return (device);
  283. }
  284.  
  285.  
  286.